package com.反转单词;

import java.util.Stack;

class Solution {
    public String reverseWords(String s) {
        char[] s1 = new char[s.length()];
        Stack<Character> stack = new Stack<Character>();
        int index=0;
        int i=0;
        while(i<s.length()){
            if(s.charAt(i)!=' '){
                stack.push(s.charAt(i));
            }
            else{
                while(!stack.empty()){
                    s1[index++]=stack.pop();
                }
                
                s1[index++]=' ';
                
                stack.clear();
            }
            i++;
        }
        System.out.println(s1.length);
        String res = new String(s1,0,s.length()-1);
        System.out.println(res.length());
        return res;
        
        
    }
}
